﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Upeu.Matricula.Data.Entities;

namespace Upeu.Matricula.Data.Mappings
{
    public class NotaMap : EntityTypeConfiguration<Nota>
    {
        public NotaMap()
        {
            //cambiar nombre table
            ToTable("nota");

            //pk
            HasKey(t => t.Id);
            Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            //campos
            Property(t=>  t.StudentId).IsRequired();
            Property(t => t.CursoId).IsRequired();
            Property(t => t.CursoNot).IsRequired();
            Property(t => t.Promedio).IsRequired();
            //relationsShips
            HasRequired(t => t.Student).WithMany(c => c.Notas).HasForeignKey(t => t.StudentId).WillCascadeOnDelete(false);
            HasRequired(t => t.Curso).WithMany(c => c.Notas).HasForeignKey(t => t.CursoId).WillCascadeOnDelete(false);
        }

    }
}
